package com.example.yls.myapplication;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.text.CollationElementIterator;

public class MainActivity extends AppCompatActivity
implements IOnTimeChangeListener{
    private Button btnStartservice;
    private TextView txtTime;
    private MyReceiver receiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.e("MainActivity", "thread id=" + Thread.currentThread().getId());
        receiver = new MyReceiver(MainActivity.this);
        IntentFilter filter = new IntentFilter();
        filter.addAction("TIME_CHANGED");
        registerReceiver(receiver, filter);
        txtTime = findViewById(R.id.txt_time);
        btnStartservice = findViewById(R.id.btn_start_service);
        btnStartservice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, MyService.class);
                startService(intent);
            }
        });
    }

    public void showTime(String str) {
        txtTime.setText(str);
    }
}


